package com.lc.hongtai.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;

import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.conn.JsonAccessToken;
import com.lc.hongtai.conn.JsonVip;
import com.lc.hongtai.toast.LovelyToast;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;

/*
* 账户管理
* */
public class AccountManagementActivity extends BaseActivity implements View.OnClickListener {

    @BoundView(R.id.account_personal_setting_ll) private LinearLayout account_personal_setting_ll;
    @BoundView(R.id.account_quota_apply_ll) private LinearLayout account_quota_apply_ll;
    @BoundView(R.id.account_borrow_ll) private LinearLayout account_borrow_ll;
    @BoundView(R.id.account_password_setting_ll) private LinearLayout account_password_setting_ll;
    @BoundView(R.id.account_safe_ll) private LinearLayout account_safe_ll;
    @BoundView(R.id.account_vip_ll) private LinearLayout account_vip_ll;
    @BoundView(R.id.account_bank_ll) private LinearLayout account_bank_ll;
    @BoundView(R.id.account_invate_ll) private LinearLayout account_invate_ll;
    @BoundView(R.id.account_message_ll) private LinearLayout account_message_ll;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account_management);

        initListener();

    }

    private void initListener() {
        account_personal_setting_ll.setOnClickListener(this);
        account_quota_apply_ll.setOnClickListener(this);
        account_borrow_ll.setOnClickListener(this);
        account_password_setting_ll.setOnClickListener(this);
        account_safe_ll.setOnClickListener(this);
        account_vip_ll.setOnClickListener(this);
        account_bank_ll.setOnClickListener(this);
        account_invate_ll.setOnClickListener(this);
        account_message_ll.setOnClickListener(this);
    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.account_personal_setting_ll:
                startVerifyActivity(PersonalSettingsActivity.class);
                break;

            case R.id.account_quota_apply_ll: //额度申请   这个荣泽 去掉了
//                startVerifyActivity(AmountApplyActivity.class);
                break;

            case R.id.account_borrow_ll:// 借款管理
              //  startVerifyActivity(BorrowManagerActivity.class);
                startVerifyActivity(BorrowManageDetailActivity.class);
                break;

            case R.id.account_password_setting_ll:
                startVerifyActivity(PasswordManageActivity.class);
                break;
            case R.id.account_safe_ll:
                startVerifyActivity(SafetyCertificateActivity.class);
                break;
            case R.id.account_vip_ll://vip隐藏了
                if (MyApplication.myPreferences.readVip_status().equals("0")) {
                    startVerifyActivity(VipApplyActivity.class);
                } else if (MyApplication.myPreferences.readVip_status().equals("2")) {
                 //   ToastUtils.show(this, "审核中");
                    LovelyToast.makeText(AccountManagementActivity.this,  "审核中", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else {
                    getVipDataAccessToken();
                }

                break;
            case R.id.account_bank_ll:
                startVerifyActivity(BankcardManagementActivity.class);
                break;
            case R.id.account_invate_ll:
                startVerifyActivity(InviteFriendsActivity.class);
                break;
            case R.id.account_message_ll:
               startVerifyActivity(MsgListActivity.class);
                break;
        }
    }

    private void getVipDataAccessToken() {
        new JsonAccessToken("user/vip", new AsyCallBack<JsonAccessToken.Info>() {
            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
               // UtilToast.show( AccountManagementActivity.this, "安全验证失败！");
                LovelyToast.makeText(AccountManagementActivity.this,  "安全验证失败!", 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);
            }
            @Override
            public void onSuccess(String toast, int type, JsonAccessToken.Info info) throws Exception {
                if (info != null) {
                    if (!TextUtils.isEmpty(info.access_token)) {
                        getVipData(info.access_token);
                    } else {
                       // UtilToast.show( AccountManagementActivity.this, "安全验证失败！");
                        LovelyToast.makeText(AccountManagementActivity.this,  "安全验证失败!", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }
                }
            }
        }).execute(this,true);

    }


    private void getVipData(String access_token) {
        new JsonVip(access_token, MyApplication.myPreferences.readUid(), new AsyCallBack<JsonVip.Info>() {
            @Override
            public void onFail(String toast, int type) throws Exception {
             //   ToastUtils.show(AccountManagementActivity.this, JsonVip.TOAST);
                LovelyToast.makeText(AccountManagementActivity.this,  JsonVip.TOAST, 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);
            }
        }).execute(AccountManagementActivity.this, true);
    }
}
